﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Perceiveit.Xml.Converters
{
    public class DelegateXConverter<T> : XConverter<T>
    {
        public Converter<string,T> ConvertFromString { get; private set; }

        public Converter<T,string> ConvertToString { get; private set; }

        public DelegateXConverter(Converter<string, T> fromString, Converter<T, string> toString)
        {
            if (null == fromString)
                throw new ArgumentNullException("fromString");
            if (null == toString)
                throw new ArgumentNullException("toString");

            this.ConvertFromString = fromString;
            this.ConvertToString = toString;
        }

        public override T FromString(string value)
        {
            return ConvertFromString(value);
        }

        public override string ToString(T value)
        {
            return ConvertToString(value);
        }
    }
}
